Revisit "Handle clicks in indentation area"
authorKristian Rietveld <kris@gtk.org>
Wed, 15 Dec 2010 22:45:04 +0000 (23:45 +0100)
committerKristian Rietveld <kris@gtk.org>
Wed, 15 Dec 2010 22:55:26 +0000 (23:55 +0100)
Check (x, y) is inside background area.  If yes, continue processing
and clamp the coordinates into cell area.  This way we will properly
handle getting a cell (which is only used for setting the focus cell)
for clicks in the indentation area (in LTR and RTL mode) and clicks
in the focus rectangle area in case focus-line-width is large.

gtk/gtktreeprivate.h
gtk/gtktreeview.c
gtk/gtktreeviewcolumn.c

index 9fe2074a0010a58be83eada300b9ffbe39ff5f22..9ee61f1ef907226654fc4b455cc05e7cefa2c319 100644 (file)
@@ -123,6 +123,7 @@ gboolean          _gtk_tree_view_column_has_editable_cell(GtkTreeViewColumn  *co
 GtkCellRenderer  *_gtk_tree_view_column_get_edited_cell  (GtkTreeViewColumn  *column);
 GtkCellRenderer  *_gtk_tree_view_column_get_cell_at_pos  (GtkTreeViewColumn  *column,
                                                           GdkRectangle       *cell_area,
+                                                          GdkRectangle       *background_area,
                                                           gint                x,
                                                           gint                y);
 
index 50d367d9a3acb58e1cd48f00ea2839e7cc0e3b67..f34d6c2be3a4e0b26aec602dd345fe36e6430aaf 100644 (file)
@@ -3135,6 +3135,7 @@ gtk_tree_view_button_press (GtkWidget      *widget,
            */
           focus_cell = _gtk_tree_view_column_get_cell_at_pos (column,
                                                               &cell_area,
+                                                              &background_area,
                                                               event->x,
                                                               event->y);
 
index 2621cb360b3d2d26e64924a2618036d8a34cd1eb..905a7bb27513ee534874b08aea8b90a0bc403231 100644 (file)
@@ -1473,19 +1473,37 @@ _gtk_tree_view_column_get_edited_cell (GtkTreeViewColumn *column)
 GtkCellRenderer *
 _gtk_tree_view_column_get_cell_at_pos (GtkTreeViewColumn *column,
                                        GdkRectangle      *cell_area,
+                                       GdkRectangle      *background_area,
                                        gint               x,
                                        gint               y)
 {
   GtkCellRenderer *match = NULL;
   GtkTreeViewColumnPrivate *priv = column->priv;
 
+  /* If (x, y) is outside of the background area, immediately return */
+  if (x < background_area->x ||
+      x > background_area->x + background_area->width ||
+      y < background_area->y ||
+      y > background_area->y + background_area->height)
+    return NULL;
+
+  /* If (x, y) is inside the background area, clamp it to the cell_area
+   * so that a cell is still returned.  The main reason for doing this
+   * (on the x axis) is for handling clicks in the indentation area
+   * (either at the left or right depending on RTL setting).  Another
+   * reason is for handling clicks on the area where the focus rectangle
+   * is drawn (this is outside of cell area), this manifests itself
+   * mainly when a large setting is used for focus-line-width.
+   */
   if (x < cell_area->x)
-    {
-      /* This can happen when we click in the "indentation".  In this
-       * case, we set x to cell_area->x, the start of the first cell.
-       */
-      x = cell_area->x;
-    }
+    x = cell_area->x;
+  else if (x > cell_area->x + cell_area->width)
+    x = cell_area->x + cell_area->width;
+
+  if (y < cell_area->y)
+    y = cell_area->y;
+  else if (y > cell_area->y + cell_area->height)
+    y = cell_area->y + cell_area->height;
 
   match = gtk_cell_area_get_cell_at_position (priv->cell_area,
                                               priv->cell_area_context,